const SERVICE = require("../../lib/js/service.js");

Page({
  data:{
    imgUrl: SERVICE.imgUrl,   //图片路径
    userInfo:wx. getStorageSync("userInfo"),    //用户信息
    LNSIZE:["0-20人","20-50人","50-100人","100-200人","200人以上"],    //公司规模
    IndustryExperience: ["1-3年","3-6年",'6-8年',"8年以上"],    //行业经验
    ExperienceType: ["独立展厅","市场商户"],   //经营类型
    LNSIZE_val: null,  //所选公司规模
    IndustryExperience_val: null,   //所选行业经验
    ExperienceType_val: null,   //所选经营类型
    Atn: ["未认证", "个体认证", "企业认证", "4S店认证", "审核中 ...", "审核不通过"],    //认证
    position: ["总经理", "销售经理", "销售总监", "渠道经理", "渠道总监", "客户经理", "人事经理", "CEO", "CHO", "CIO", "CCO","CMO"],
    position_val: null
  },

  onLoad(){
    // this.getCompanyInfo();
  },

  onShow(){
    this.getCompanyInfo();
  },

  /*分享*/ 
  onShareAppMessage(){},
  
  /*获取公司信息*/
  getCompanyInfo(){
    let _this = this;
    wx.showNavigationBarLoading();
    SERVICE.POST(SERVICE.URL.getCompanyInfo,{
      thirdCookie: wx.getStorageSync("thirdCookie")
    },(sataus,res)=>{
      wx.hideNavigationBarLoading();
      console.log(res);
      if(res.data.status == "success"){
        _this.setData({
          CompanyInfo: res.data.company_info
        });
      }else{
        wx.showToast({
          title: "获取公司信息失败",
          icon: "none",
          mask: true
        });
      }
    });
  }, 

  /*获取公司规模*/
  getLNSIZE(e){
    let td = this.data;
    this.setData({
      LNSIZE_val: td.LNSIZE[e.detail.value]
    });
    this.compileInfo({
      thirdCookie: wx.getStorageSync("thirdCookie"),
      scale: td.LNSIZE[e.detail.value]
    });
  },

  /*获取行业经验*/
  getIndustryExperience(e){
    let td = this.data;
    this.setData({
      IndustryExperience_val: td.IndustryExperience[e.detail.value]
    });
    this.compileInfo({
      thirdCookie: wx.getStorageSync("thirdCookie"),
      experience: td.IndustryExperience[e.detail.value]
    });
  },

  /*获取经营类型*/ 
  getExperienceType(e){
    let td = this.data;
    this.setData({
      ExperienceType_val: td.ExperienceType[e.detail.value]
    });
    this.compileInfo({
      thirdCookie: wx.getStorageSync("thirdCookie"),
      genre: td.ExperienceType[e.detail.value]
    });
  },
  
  /*年周转量*/
  turnover(e){
    this.compileInfo({
      thirdCookie: wx.getStorageSync("thirdCookie"),
      turnover: e.detail.value
    });
  },

  

  /*认证*/
  certification(){
    let td = this.data;
    if (td.userInfo.certification == 0){
      wx.navigateTo({
        url: ""
      });
    }
  },

  /*编辑信息*/ 
  compileInfo(params){
    wx.showLoading({
      title: "编辑中...",
      mask: true
    });
    SERVICE.POST(SERVICE.URL.myCompany, params,(status,res)=>{
      console.log("编辑信息:",res);
      wx.hideLoading();
      if(res.data.status != "success"){
        wx.showToast({
          title: "编辑失败",
          icon: "none",
          mask: true
        });
      }
    });
  },

  /*编辑公司信息*/
  complieCompanyInfo(){
    let td = this.data;
    wx.navigateTo({
      url: "../describe/describe?info=" + td.CompanyInfo.describe + '&title=公司介绍',
    });
  },

  /*一句话介绍*/
  complieCompanyIntro(){
    let td = this.data;
    wx.navigateTo({
      url: "../describe/describe?info=" + td.CompanyInfo.intro + '&title=一句话介绍',
    });
  },

  myPosition(e){
    let td = this.data, position_val = e.detail.value;
    console.log(td.position[position_val]);
    this.setData({
      position_val: td.position[position_val]
    });
    this.compileInfo({
      thirdCookie: wx.getStorageSync("thirdCookie"),
      my_position: td.position[position_val]
    });
  }
});